<!DOCTYPE html>
<html>
    <head>
	  <title>塔机监控</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta http-equiv="Content-Language" content="zh-CN" />
      <meta http-equiv="Content-Script-Type" content="text/javascript" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
      <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
      <meta name="format-detection" content="telephone=no"/>
	 <link rel="stylesheet" href="css/bootstrap.min.css">
	 <link rel="stylesheet" type="text/css" href="css/index.css"/>
	 <link rel="stylesheet" href="css/swiper.min.css">
	 <script src="js/swiper.min.js"></script>
	 <style>
		.title_top{text-align: center;}
		.rq{padding: 0;}
		.rq a{color: #FFF;}
		.projectname{font-size:17px;font-weight:bolder;margin-top:20px;}
	 </style>
    </head> 
	<body class="body_2"> 
		<div class="col-xs-12 title_top">
			<div class="col-xs-3 rq back">
				<a href="javascript:history.back(-1)">
					<div style="float: left;"><img src="images/icon_left.png"/></div>
					<div style="float: left;margin-top: 2px;">返回</div>
				</a>
			</div>
			<div class="col-xs-6">塔机监控</div>
			<div class="col-xs-3"></div>
		</div>
		<div class="col-xs-12 monitor" style="margin-top: 60px;">
			<div class="col-xs-12 monitor_titl projectname" >项目名称</div>
			<div class="col-xs-12 monitor_top_1 builders">施工单位：施工单位名称</div> 
			<div class="col-xs-12 monitor_top_1 address">项目地址：项目地址</div>
			<div class="col-xs-12 monitor_monitor lists">
			</div>
		</div>
	</body>
</html>
<script src="js/mui.min.js"></script>
<script src="js/project.config.js"></script>
<script src="js/jquery.min.js"></script>
<script>
    mui.plusReady(function () {
        var token = get_token();
		var params = get_ws();
		if(!params.projectID){
			_mui_dialog._toast('请勿非法访问');
			return false;
		}
		//时间戳
		var today_start_time = today_end_time = week_start_time = week_end_time = '';
		mui.ajax(project_cofnig.service_time, {
			async: false,
			dataType: 'json',
			data: {},
			success: function (ref) {
				today_start_time = ref.start_today;
				today_end_time = ref.end_today;
			}
		});
		mui.ajax(project_cofnig.service_past_time, {
			async: false,
			dataType: 'json',
			data: {type:7},
			success: function (ref) {
				week_start_time = ref.start_time;
				week_end_time = ref.end_time;
			}
		});
		//项目详情
		var data = {};
        data.api = 'project-details-info';
        data.token = token;
        data.projectID = params.projectID;
		mui.ajax(project_cofnig.service_url, {
			async: true,
			dataType: 'json',
			data: data,
			success: function (ref) {
				if (ref.code == 0) {
					$.each(ref.data.project,function(i,v){
						$(".projectname").html(v.projectname);
						$(".builders").html('施工单位：'+v.builders);
						$(".address").html('项目地址：'+v.address);
					});
				} else {
					_mui_dialog._toast(ref.message);
				}
				return false;
			}
		});
		//塔机详情
		data.api = 'tower-get-device';
        mui.ajax(project_cofnig.service_url, {
            async: true,
            dataType: 'json',
            data: data,
            success: function (ref) {
                if (ref.code == 0) {
                    var _html = '';
					_html += '<div class="swiper-container">';
					_html += '<div class="swiper-wrapper">';			
                    mui(ref.data.towers).each(function (i, v) {	
						//塔机统计数据
						var data = {};
						data.token = token;
						data.towerID = v.towerID;
						data.api = 'tower-get-work-cycle-statisticsInfo';
						data.startTime = week_start_time;
						data.endTime = week_end_time;
						data.justCount = 1;
						var totalWorkCount = alarmWorkCount = todayWorkCount = todayAlarmCount = 0;// 总吊装次数,违章吊装次数
						//今日吊装次数,今日违章吊装次数
						mui.ajax(project_cofnig.service_url, {
							async: false,
							dataType: 'json',
							data: data,
							success: function (ref) {
								totalWorkCount = ref.data.totalWorkCount;
								alarmWorkCount = ref.data.alarmWorkCount;
								todayWorkCount = ref.data.todayWorkCount;
								todayAlarmCount = ref.data.todayAlarmCount;
							}
						});
						var statusDesColor = '';
						switch(v.statusDesc){
							case '报警':
								statusDesColor = '#DC143C';
								break;
							case '预警':
								statusDesColor = '#FF8C00';
								break;
							case '离线':
								statusDesColor = '#808080';
								break;
							case '违章':
								statusDesColor = '#FFFF00';
								break;
							default:
								statusDesColor = '#90EE90';
								break;
						}
						_html += '<div class="swiper-slide" data-towerid="'+v.towerID+'"">';
						_html += '<div class="col-xs-12 monitor_monitor_top_1">';
						_html += ' <div class="col-xs-3 monitor_monitor_top_left">';
						_html += '<img src="images/img_img_1.png" />';  
						_html += '</div>';     
						_html += '<div class="col-xs-9 monitor_monitor_top_right">';          
						_html += '<div class="monitor_monitor_p_1">塔机备案：<span>'+v.recordNum+'</span>';     
						_html += '<div class="monitor_monitor_p_3" style="color:'+statusDesColor+'" >'+v.statusDesc+'</div>';      
						_html += '</div>';          
						_html += ' <p class="monitor_monitor_p_2">塔机驾驶：'+v.driverName+'</p>';              
						_html += '</div>';    
						_html += '</div>';    
						_html += '<div class="col-xs-7 monitor_monitor_top_2">';         
						_html += '<p class="monitor_monitor_p_4">黑匣子ID：<span>'+v.blackBoxID+'</span></p>';
						_html += '<p class="monitor_monitor_p_4">当前载重：<span>'+v.weight+'吨</span></p>';
						_html += '<p class="monitor_monitor_p_4">安全载重：<span>'+v.safeWeight+'吨</span></p>';
						_html += '<p class="monitor_monitor_p_4">当前力矩：<span>'+v.force+'吨/米</span></p>';  
						_html += '<p class="monitor_monitor_p_4">小车变幅：<span>'+v.distance+'米</span></p>';
						_html += ' <p class="monitor_monitor_p_4">塔臂回旋：<span>'+v.angle+'度</span></p>';
						_html += ' <p class="monitor_monitor_p_4">现场风速：<span>'+v.windSpeed+'米/秒</span></p>';
						_html += ' </div>';
						_html += '<div class="col-xs-5 monitor_monitor_top_3">';
						_html += '<img src="images/bg_td.png" />';
						_html += '</div>';
						_html += '<div class="col-xs-12 monitor_monitor_top_4">';
						_html += '<div class="col-xs-6 monitor_monitor_top_4_left">';
						_html += ' <div class="col-xs-12 a_a total" data-status="0" data-type="today"><a href="javascript:;">今日吊装：'+todayWorkCount+'次</a></div>';
						_html += '<div class="col-xs-12 a_b total" data-status="0" data-type="week" ><a href="javascript:;">本周吊装：'+totalWorkCount+'次</a></div>';
						_html += ' </div>';
						_html += '<div class="col-xs-6 monitor_monitor_top_4_right">';
						_html += '<div class="col-xs-12 a_a total" data-status="F" data-type="today" ><a href="javascript:;">今日违章：'+todayAlarmCount+'次</a></div>';
						_html += '<div class="col-xs-12 a_b total" data-status="F" data-type="week" ><a href="javascript:;">本周违章：'+alarmWorkCount+'次</a></div>';
						_html += '</div>';
						_html += '</div>';
						_html += '</div>';
});
						_html += ' </div>';
						_html += '</div>';
						$(".lists").append(_html);
						var swiper = new Swiper('.swiper-container', {
								slidesPerView: 1.1,
								spaceBetween: 5,
								freeMode : true,
								observer: true,//修改swiper自己或子元素时，自动初始化swiper
								observeParents: true//修改swiper的父元素时，自动初始化swiper
							});
		                } else {
							_mui_dialog._toast(ref.message);
		                }
		                return false;
            }
        });
		//统计详情
		mui("body").on('tap','.total',function(){
			var _this = $(this);
			var towerID = _this.parents(".swiper-slide").data('towerid');
			var status = _this.data('status');
			var type = _this.data('type');
			var start_time = (type == 'today' ? today_start_time : week_start_time);
			var end_time = (type == 'today' ? today_end_time : week_end_time);
			redirect('t_log.html',{
				towerID:towerID,
				status:status,
				startTime:start_time,
				endTime:end_time,
			});
		});	
		mui(".title_top").on("tap",".back",function(){
			mui.back();
		});
    });
</script>
		 